home *** CD-ROM | disk | FTP | other *** search
- /* td.c */
-
- /* simplified screen driver for jove. */
- /* JOVE/MSDOS. K. Mitchum 1/85 */
- /* Ken Mitchum */
- /* University of Pittsburgh */
- /* Decision Systems Laboratory */
-
- #include "tec.h"
- #include "tm.h"
- #include "td.h"
-
- unsigned char *abstoptr();
-
-
- #define MAXCOL 79
- #define NATTR 0x0700 /* normal white on black */
- #define HATTR 0x0900 /* highlight */
- #define BLANK (defattr | 0x20)
- #define tchar(p) (((p) & 0x7f) | tattr)
- #define RLENB 160
-
- typedef unsigned tscn[][MAXCOL+1];
-
- #ifdef HARDINIT
- short tbig[] = MA80X43;
- short tsmall[] = MA80X25;
- #endif
-
- static unsigned maxrow;
- static unsigned tattr; /* attibute for char */
- static unsigned defattr, hltattr;
- static unsigned trow, tcol;
- static unsigned insert;
- static unsigned base;
- static tscn *screen;
-
-
- static hardinit(x) /* hardware initialization */
- int *x;
- {
- int i,n;
-
- #ifdef HARDINIT
- outportb(msr,1);
- n = *x++;
- outportb(xmsr,*x++);
- for(i = 0; i < 14; i++) {
- outportb(ptrl,i);
- outportb(datal,*x++);
- }
- sleep(1);
- outportb(msr,n);
- #endif
- return;
- }
-
-
- static softinit(rows,inverse)
- int rows, inverse;
- {
- maxrow = rows -1;
- insert = 0;
- defattr = NATTR;
- hltattr = HATTR;
- tattr = defattr;
- if(inverse) toggle();
- screen = (tscn *) abstoptr(PAGEBASE);
- wipescreen();
- return;
- }
-
-
- static toggle()
- {
- unsigned attr = defattr;
- defattr = hltattr;
- hltattr = attr;
- return;
- }
-
-
- static wipescreen() /* clear and home */
- {
- unsigned row, col;
- unsigned p = BLANK;
- int len;
- int *pos = &(*screen)[0][0];
- len = (maxrow +1) * (MAXCOL +1);
- while(len--) *pos++ = BLANK;
-
- /* for(row = 0; row <= maxrow; row++)
- for(col = 0; col <= MAXCOL; col++) (*screen)[row][col] = p;
- */
- putcurs(0,0);
- return;
- }
-
- static putcurs(row,col)
- unsigned row, col;
- {
- static unsigned addr;
- if((row > maxrow) || (col > MAXCOL)) return(ERROR);
- trow = row;
- tcol = col;
- addr = row * 80 + col;
- outportb(ptrl,14);
- outportb(datal,(addr & 0xff00) >> 8);
- outportb(ptrl,15);
- outportb(datal,(addr & 0xff));
- return(0);
- }
-
-
- putp(p) /* put one character, advance cursor */
- char p;
- {
- static unsigned col;
- if(insert) movmem(&(*screen)[trow][tcol],&(*screen)[trow][tcol+1],
- (MAXCOL - tcol) *2);
- /*
- if(insert) for(col = tcol; col < MAXCOL; col++)
- (*screen)[trow][col+1] = (*screen)[trow][col];
- */
- (*screen)[trow][tcol] = tchar(p);
-
- if(tcol < MAXCOL) putcurs(trow,tcol+1);
- return;
- }
-
- static wipeline() /* clear to end of line */
- {
-
- int len;
- int *pos = &(*screen)[trow][tcol];
- len = MAXCOL - tcol +1;
- while(len--) *pos++ = BLANK;
- return;
- }
-
- static clreos() /* clear to end of screen */
- {
- unsigned row, col;
- row = trow;
- col = tcol;
- while(row <= maxrow) {
- while(col <= MAXCOL) (*screen)[row][col] = BLANK;
- col = 0;
- row++;
- }
- return;
- }
-
-
- static delchars(n)
- int n;
- {
- unsigned col;
- for(col = tcol; col < MAXCOL; col++)
- (*screen)[trow][col] = (*screen)[trow][col+1];
- (*screen)[trow][MAXCOL] = BLANK;
- return;
- }
-
-
- static dellines(n,bot)
- int n,bot;
- {
- static unsigned char *src, *dest;
- static int len;
- static unsigned row, col;
-
- dest = &(*screen)[trow][0];
- src = &(*screen)[trow+n][0];
- len = (bot - trow -n +1) * RLENB;
- movmem(src,dest,len);
- for(row = bot -n +1; row <= bot; row++)
- for(col = 0; col <= MAXCOL; col++) (*screen)[row][col] = BLANK;
- putcurs(trow,0);
- return;
- }
-
- static inslines(n,bot)
- int n, bot;
- {
- static unsigned char *src, *dest;
- static int len;
- static unsigned row, col;
-
- src = &(*screen)[trow][0];
- dest =&(*screen)[trow +n][0];
- len = (bot -trow -n +1) * RLENB;
- movmem(src,dest,len);
- for(row = trow; row < trow +n; row++)
- for(col = 0; col <= MAXCOL; col++) (*screen)[row][col] = BLANK;
- putcurs(trow,0);
- return;
- }
-
-
- static
- INSmode(new)
- int new;
- {
- insert = new;
- }
-
- static
- HLmode(new)
- int new;
- {
- if(new) tattr = hltattr;
- else tattr = defattr;
- }
-
-
-
- blanks(n)
- int n;
- {
- while(n--) putp(' ');
- return;
- }
-
- init()
- {
- softinit(tt.t_length,0);
- base = PBASE;
- #ifdef HARDINIT
- hardinit(tbig);
- #endif
- return;
- }
-
- reset()
- {
- }
-
- cleanup()
- {
- softinit(43,0);
- #ifdef HARDINIT
- hardinit(tsmall);
- #endif
- return;
- }
-
- writechr(start,end)
- char *start, *end;
- {
- static int len, plen;
- static int *pos;
- plen =len = end -start +1;
-
- pos = &(*screen)[trow][tcol];
- if(insert) movmem(pos,pos +len,(MAXCOL - tcol -len +1)*2);
- while(len--) *pos++ = tchar(*start++);
- putcurs(trow,tcol + plen);
- return;
- }
-
-
- Trm () {
- tt.t_length = MAXROW +1;
- tt.t_INSmode = INSmode;
- tt.t_HLmode = HLmode;
- tt.t_inslines = inslines;
- tt.t_dellines = dellines;
- tt.t_blanks = blanks;
- tt.t_init = reset;
- tt.t_cleanup = cleanup;
- tt.t_wipeline = wipeline;
- tt.t_wipescreen = wipescreen;
- tt.t_topos = putcurs;
- tt.t_reset = reset;
- tt.t_delchars = delchars;
- tt.t_writechars = writechr;
- tt.t_window = 0;
- tt.t_width = 80;
- init();
- return(tt.t_length);
- }
-
- /* end */